package com.ruoyi.project.storage.storageapp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.storage.storageapp.domain.App;
import com.ruoyi.project.storage.storageapp.service.IAppService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 应用列表Controller
 * 
 * @author shixiangwen
 * @date 2020-02-27
 */
@Controller
@RequestMapping("/storage/storageapp")
public class AppController extends BaseController {
	private String prefix = "storage/storageapp";

	@Autowired
	private IAppService appService;

	@RequiresPermissions("storage:storageapp:view")
	@GetMapping()
	public String storageapp() {
		return prefix + "/storageapp";
	}

	/**
	 * 查询应用列表列表
	 */
	@RequiresPermissions("storage:storageapp:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(App app) {
		startPage();
		List<App> list = appService.selectAppList(app);
		return getDataTable(list);
	}

	/**
	 * 导出应用列表列表
	 */
	@RequiresPermissions("storage:storageapp:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(App app) {
		List<App> list = appService.selectAppList(app);
		ExcelUtil<App> util = new ExcelUtil<App>(App.class);
		return util.exportExcel(list, "storageapp");
	}

	/**
	 * 新增应用列表
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存应用列表
	 */
	@RequiresPermissions("storage:storageapp:add")
	@Log(title = "应用列表", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(App app) {
		return toAjax(appService.insertApp(app));
	}

	/**
	 * 修改应用列表
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap) {
		App app = appService.selectAppById(id);
		mmap.put("app", app);
		return prefix + "/edit";
	}

	/**
	 * 修改保存应用列表
	 */
	@RequiresPermissions("storage:storageapp:edit")
	@Log(title = "应用列表", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(App app) {
		return toAjax(appService.updateApp(app));
	}

	/**
	 * 删除应用列表
	 */
	@RequiresPermissions("storage:storageapp:remove")
	@Log(title = "应用列表", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(appService.deleteAppByIds(ids));
	}
}
